<template>
  <div class="form-comp">

    <el-select v-model="compValue" filterable  class="m-2"  :disabled="disabled">
      <el-option
          v-for="item in options"
          :key="item.id"
          :label="item.name"

          :value="item.id"
      />
    </el-select>
  </div>
</template>

<script lang="ts" setup>
defineOptions({
  name: "FormUserSelect"
});
// @ts-ignore
import {ref, onMounted, getCurrentInstance, watchEffect, watch} from 'vue'

const props = defineProps({
  value: {type: Object, required: true},
  disabled: {type: Boolean, required: false},
  multiple: {type: Boolean, required: false, default: false},
  regionCode:{type: String, required: false, default: false},
  roleCode:{type: String, required: false, default: false},

});

const compValue = ref<any>(props.value);

const options = ref<any>([]);
const emit = defineEmits(['update:value'])

// @ts-ignore
let {proxy} = getCurrentInstance()
//监听变化返回
watch(() => compValue.value, () => {
  emit("update:value", compValue.value + "")
})
onMounted(() => {
  loadData();
})

//获取字典列表
function loadData() {
  let params:any={};
  if(props.roleCode){
    params.roleCode=props.roleCode;
  }
  if(props.regionCode){
    params.regionCode=props.regionCode;
  }
  proxy.$http.post("/user-center/user/findList", params).then((res: any) => {
    options.value = res.data;
    compValue.value = props.value;
  });
}

</script>